$('.right-titleicon').on("click", function(e) {
	projectVM.showMenulist()
})
 
 var cloak = ''
projectVM = new Vue({
	el: "#content",
	    filters:{
	      times: function (dataStr){
	       var time = new Date(dataStr);
	          
	            function timeAdd0(str) {
	              if (str < 10) {
	                str = '0' + str;
	              }
	              return str
	            }
	            var y = time.getFullYear();
	            var m = time.getMonth() + 1;
	            var d = time.getDate();
	            var h = time.getHours();
	            var mm = time.getMinutes();
	            var s = time.getSeconds(); 
	            return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) ;
	      },
},
	data: {
		companyName:'',
		companyCode:'',
		recordId:'',
		isEdit:false,
		stopDuration:'',
		lostPower:'',
		oneLostPower:'',
		unlimitDuration:'',
		stationList:[],
		stationName:'',
		stationCode:'',
		dealProgress:'',
		cause:'',
		pulseonTime:'',
		isNewFault:'',
		repairCost:'',
		dealBegTime:'',
		dealEndTime:'',
		createDate:'',
		shutDownTypename:'',
		shutdownType:'',
		hv:'',
		lastEditName:'',
		projectNo:'',
		list:[],
		shutdownTime:'',
		keyWords:'',
		faultTypename:'',
		faultType:'',
		faultCode:'',
		faultName:'',
		systemTypename:'',
		systemType:'',
		nowDate:'',
		filterText:'',
		currentUser:'',
		deviceCode:'',
		deviceType:'',
		showAddform:false,
		islook:false,
		status:0,
		pageIndex:1,
		role:'',
		roles:'',
		faultSysArray:[
		        {text:'变桨系统',value:'1'},
		        {text:'变频系统',value:'2'},
		        {text:'控制系统',value:'3'},
		        {text:'液压系统',value:'4'},
		        {text:'齿轮箱',value:'5'},
		        {text:'发电机',value:'6'},
		
		],
		shutdownTypeArray:[
		        {text:'故障停机',value:'1'},
		        {text:'受累停机',value:'2'},
		        {text:'限负荷停机',value:'3'},
		],
		brand: [
		        {name: '集控运行'},
		        {id:'blowerDownBoostAdd',name: '模板'}
		],
	},
	components: {
		personselect,
		processlog
	},
	
	created() {
		this.currentUser = JSON.parse(localStorage.getItem('neiosUser'))
		console.log(JSON.stringify(this.currentUser))
		this.roles = this.currentUser.roles
		this.lastEditName = this.currentUser.name
		if(this.roles.indexOf('NEIOS_AREA_COMPANY')>=0){
			this.companyCode = this.currentUser.companyNewCode
			this.companyName = this.currentUser.companyName
			this.role = 'company'
		}
		else if(this.roles.indexOf('NEIOS_STATION')>=0){
			this.companyCode = this.currentUser.companyNewCode
			this.companyName = this.currentUser.companyName
			this.stationCode = this.currentUser.stationNewCode
			this.stationName = this.currentUser.stationNewName
			this.role = 'station'
		}
		else{
		
			this.role = 'total'
		}
		console.log(this.role)
		this.getList()
		this.getNowdate()
		// this.getStationList()
		this.getCompany()
	}, 
	methods: {
		//选择所属区域
		showCompany(){
			var that = this
			if(this.role != 'total'){
				return
			}
			 let picker = new mui.PopPicker({
				 layer:1
			 })
			 picker.setData(this.companyList)
			  picker.show(function(e) {   //e 就是总数据的数组 显示picker
			  
				that.companyName = e[0].text
				that.companyCode = e[0].value
				that.stationCode = ''
				that.stationName= ''
				that.getStationList()
			})
		},
		//获取分公司列表
		getCompany(){
			var that = this
			var param = {
				orgType:'1',
				parentOrgCode:'',
				parentOrgType:''
			}							 
			mui.neiosRequst.httpRequst('/common/organization/getOrganizationListByType', param,
				(data)=> {
					
				if(data.code ==  0){	
					let arr = []
					data.data.forEach(item=>{
						arr.push({
							text:item.newOrgName,
							value:item.newOrgCode
						})
					})
					that.companyList = arr
				}
				else{
					mui.toast(data.msg)
				}
		
				},
				function(data) {
				
				})
		},
		//查看
		look(e){
			this.islook = true
			this.recordId = e.recordId
			this.showAddform = true
			this.stationCode=e.stationCode,
			this.stationName=e.stationName,
			this.deviceCode=e.deviceCode,
			this.deviceType=e.deviceType,
			this.projectNo=e.projectNo,
			this.shutdownType=e.shutdownType,
			this.shutdownTypeArray.forEach(item=>{
				if(e.shutdownType == item.value){
					this.shutDownTypename = item.text
				}
			})
			this.faultName=e.faultName,
			this.faultCode=e.faultCode,
			this.faultType=e.faultType,
			this.shutdownTime=this.toDate(e.shutdownTime),
			this.dealBegTime=this.toDate(e.dealBegTime),
			this.dealEndTime=this.toDate(e.dealEndTime),
			this.repairCost=e.repairCost,
			this.pulseonTime=this.toDate(e.pulseonTime),
			this.isNewFault=e.isNewFault,
			this.cause=e.cause,
			this.dealProgress=e.dealProgress,
			this.stopDuration=e.stopDuration,
			this.lostPower=e.lostPower,
			this.oneLostPower=e.oneLostPower,
			this.unlimitDuration=e.unlimitDuration,
			this.faultSys=e.faultSys
			this.faultSysArray.forEach(item=>{
				if(e.faultSys == item.value){
					this.systemTypename = item.text
				}
			})
		},
		//时间戳转换
		toDate(dataStr){
			var time = new Date(dataStr);
			   
			     function timeAdd0(str) {
			       if (str < 10) {
			         str = '0' + str;
			       }
			       return str
			     }
			     var y = time.getFullYear();
			     var m = time.getMonth() + 1;
			     var d = time.getDate();
			     var h = time.getHours();
			     var mm = time.getMinutes();
			     var s = time.getSeconds(); 
			     return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) ;
		},
		//更新
		update(){
			var that = this
			if(this.stationCode == ''){
				mui.toast('请选择场站')
				return
			}
			else if(this.deviceCode == ''){
				mui.toast('请输入风机编号')
				return
			}
			else if(this.projectNo == ''){
				mui.toast('请输入期数')
				return
			}
			else if(this.deviceType == ''){
				mui.toast('请选择风机类型')
				return
			}
			else if(this.shutdownType == ''){
				mui.toast('请选择停机类型')
				return
			}
			else if(this.faultName == ''){
				mui.toast('请输入故障名称')
				return
			}
			else if(this.faultCode == ''){
				mui.toast('请输入故障代码')
				return
			}
			else if(this.faultType == ''){
				mui.toast('请输入故障类别')
				return
			}
			else if(this.systemTypename == ''){
				mui.toast('请选择故障所属系统')
				return
			}
			else if(this.shutdownTime == ''){
				mui.toast('请选择故障停机时间')
				return
			}
			else if(this.dealBegTime == ''){
				mui.toast('请选择开始处理时间')
				return
			}
			else if(this.dealEndTime == ''){
				mui.toast('请选择处理结束时间')
				return
			}
			else if(this.isNewFault == ''){
				mui.toast('请选择是否新报故障')
				return
			}
			var param = {
						recordId:this.recordId,
					   newAreaCode:this.currentUser.companyNewCode,
				       areaCompanyName:this.currentUser.companyName,
				       newStationCode:this.stationCode,
				       stationName:this.stationName,
				       biztypeId:'RSP',
				       deviceCode:this.deviceCode,
				       deviceType:this.deviceType,
				       projectNo:this.projectNo,
				       shutdownType:this.shutdownType,
				       faultName:this.faultName,
				       faultCode:this.faultCode,
				       faultType:this.faultType,
				       shutdownTime:this.shutdownTime,
				       dealBegTime:this.dealBegTime,
				       dealEndTime:this.dealEndTime,
				       repairCost:this.repairCost,
				       pulseonTime:this.pulseonTime,
				       isNewFault:this.isNewFault,
				       cause:this.cause,
				       dealProgress:this.dealProgress,
				       stopDuration:this.stopDuration,
				       lostPower:this.lostPower,
				       oneLostPower:this.oneLostPower,
				       unlimitDuration:this.unlimitDuration,
				       lastEditCode:this.currentUser.userId,
				       lastEditName:this.currentUser.name,
				       lastEditTime:this.nowDate,
				       faultSys:this.faultSys,
			}  
			mui.neiosRequst.httpRequst('/app/neiosShutdownRecord/update', param,
							(data)=> {
								if(data.code == 0){
									mui.toast('操作成功')
									that.getList()
									that.showAddform = false
								}
								else{
									mui.toast(dat.msg)
								}
							},
							function(data) {
			   
							})
		},
		//编辑
		edit(e){
			this.isEdit = true
			this.recordId = e.recordId
			this.showAddform = true
			this.companyName = e.areaCompanyName
			this.companyCode = e.newAreaCode
			this.stationCode=e.stationCode,
			this.stationName=e.stationName,
			this.deviceCode=e.deviceCode,
			this.deviceType=e.deviceType,
			this.projectNo=e.projectNo,
			this.shutdownType=e.shutdownType,
			this.shutdownTypeArray.forEach(item=>{
				if(e.shutdownType == item.value){
					this.shutDownTypename = item.text
				}
			})
			this.faultName=e.faultName,
			this.faultCode=e.faultCode,
			this.faultType=e.faultType,
			this.shutdownTime=this.toDate(e.shutdownTime),
			this.dealBegTime=this.toDate(e.dealBegTime),
			this.dealEndTime=this.toDate(e.dealEndTime),
			this.repairCost=e.repairCost,
			this.pulseonTime=this.toDate(e.pulseonTime),
			this.isNewFault=e.isNewFault,
			this.cause=e.cause,
			this.dealProgress=e.dealProgress,
			this.stopDuration=e.stopDuration,
			this.lostPower=e.lostPower,
			this.oneLostPower=e.oneLostPower,
			this.unlimitDuration=e.unlimitDuration,
			this.faultSys=e.faultSys
			this.faultSysArray.forEach(item=>{
				if(e.faultSys == item.value){
					this.systemTypename = item.text
				}
			})
		},
		//确认
		confirm(e){
			var that = this
			var param = {
				confirmedCode:this.currentUser.name,
				confirmedName:this.currentUser.name,
				recordId:e.recordId
			}
			mui.neiosRequst.httpRequst('/app/neiosShutdownRecord/confirm', param,
							(data)=> {
								if(data.code == 0){
									mui.toast('操作成功')
									that.getList()
								}
								else{
									mui.toast(dat.msg)
								}
							},
							function(data) {
			   
							})
		},
		//获取场站列表
		getStationList(){
			var that = this
			var param = {
				orgType:2,
				parentOrgCode:this.companyCode,
				parentOrgType:this.currentUser.orgType
			}
			mui.neiosRequst.httpRequst('/common/organization/getOrganizationListByType', param,
							(data)=> {
				var list = data.data
				var arr = []
				list.forEach(item=>{
					arr.push({
						value:item.newOrgCode,
						text:item.newOrgName
					})
				})
				that.stationList = arr
							},
							function(data) {
			   
							})
			
		},
		//选择启动时间
		choosepulTime(){
			var that = this 
			var dtPicker = new mui.DtPicker({
				type: 'date'
			});
			dtPicker.show(function(selectItems) {
				that.pulseonTime=selectItems.text
			})
		},
		//选择故障停机时间
		chooseTime(){
			var that = this
			var dtPicker = new mui.DtPicker({
				type: 'date'
			});
			dtPicker.show(function(selectItems) {
			that.shutdownTime=selectItems.text
			})
		},
		//选择开始处理时间
		choosebegTime(){
			var that = this
			var dtPicker = new mui.DtPicker({
				type: 'date'
			});
			dtPicker.show(function(selectItems) {
				that.dealBegTime=selectItems.text
			})
		},
		//选择结束处理时间
		chooseendTime(){
			var that = this
			var dtPicker = new mui.DtPicker({
				type: 'date'
			});
			dtPicker.show(function(selectItems) {
				that.dealEndTime=selectItems.text
			})
		},
		//选择场站
		showStationType(){
			var that = this
			if(this.role == 'station'){
				return
			}
			 let picker = new mui.PopPicker({
				 layer:1
			 })
			 picker.setData(this.stationList)
			  picker.show(function(e) {   //e 就是总数据的数组 显示picker
			  
				that.stationName = e[0].text
				that.stationCode = e[0].value
			})
		},
		//选择停机类型
		showShutType(index){
			var that = this
			 let picker = new mui.PopPicker({
				 layer:1
			 })
			 picker.setData(this.shutdownTypeArray)
			  picker.show(function(e) {   //e 就是总数据的数组 显示picker
				that.shutdownType = e[0].value
				that.shutDownTypename = e[0].text
			})
		
		},
		//选择故障所属系统
		showSystemType(index){
			var that = this
			 let picker = new mui.PopPicker({
				 layer:1
			 })	
			 picker.setData(this.faultSysArray)
			  picker.show(function(e) {   //e 就是总数据的数组 显示picker
				that.faultSys = e[0].value
				that.systemTypename = e[0].text
			})
		},
		//获取当前时间
		getNowdate() {
			var date = new Date()
			var year = date.getFullYear()
			var month = date.getMonth()
			var day = date.getDate()
			var hour = date.getHours()
			var min = date.getMinutes()
			 var sec = date.getSeconds()
			month = month*1 + 1
			if (month.toString().length < 2) {
				month = '0' + month
			}
			if (day.toString().length < 2) {
				day = '0' + day
			}
			if (hour.toString().length < 2) {
				hour = '0' + hour
			}
			if (min.toString().length < 2) {
				min = '0' + min
			}
			if (sec.toString().length < 2) {
				sec = '0' + sec
			}
			this.nowDate = year + '-' + month + '-' + day
		},
		changeEdittime(){
			var dtPicker = new mui.DtPicker({
				type: 'date'
			});
			dtPicker.show(function(selectItems) {
				console.log(JSON.stringify(selectItems))
				$("#editTime").text(selectItems.text);
			})
		},
		//修改列表状态
		changeStatus(e){
			this.status = e
			this.getList()
		},
		//输入框搜索
		onChange(e){
			clearTimeout(cloak)
		this.page = 1
		this.list = []
		cloak = setTimeout(() => {
			this.getList()
		}, 500);
		},
		//添加至列表
		addList(){
			var that = this
			if(this.companyCode == ''){
				mui.toast('请选择区域')
				return
			}
			else if(this.stationCode == ''){
				mui.toast('请选择场站')
				return
			}
			else if(this.deviceCode == ''){
				mui.toast('请输入风机编号')
				return
			}
			else if(this.projectNo == ''){
				mui.toast('请输入期数')
				return
			}
			else if(this.deviceType == ''){
				mui.toast('请选择风机类型')
				return
			}
			else if(this.shutdownType == ''){
				mui.toast('请选择停机类型')
				return
			}
			else if(this.faultName == ''){
				mui.toast('请输入故障名称')
				return
			}
			else if(this.faultCode == ''){
				mui.toast('请输入故障代码')
				return
			}
			else if(this.faultType == ''){
				mui.toast('请输入故障类别')
				return
			}
			else if(this.systemTypename == ''){
				mui.toast('请选择故障所属系统')
				return
			}
			else if(this.shutdownTime == ''){
				mui.toast('请选择故障停机时间')
				return
			}
			else if(this.dealBegTime == ''){
				mui.toast('请选择开始处理时间')
				return
			}
			else if(this.dealEndTime == ''){
				mui.toast('请选择处理结束时间')
				return
			}
			else if(this.isNewFault == ''){
				mui.toast('请选择是否新报故障')
				return
			}
			var param = {
					   newAreaCode:this.currentUser.companyNewCode,
				       areaCompanyName:this.currentUser.companyName,
				       newStationCode:this.stationCode,
				       stationName:this.stationName,
				       biztypeId:'RSP',
				       deviceCode:this.deviceCode,
				       deviceType:this.deviceType,
				       projectNo:this.projectNo,
				       shutdownType:this.shutdownType,
				       faultName:this.faultName,
				       faultCode:this.faultCode,
				       faultType:this.faultType,
				       shutdownTime:this.shutdownTime,
				       dealBegTime:this.dealBegTime,
				       dealEndTime:this.dealEndTime,
				       repairCost:this.repairCost,
				       pulseonTime:this.pulseonTime,
				       isNewFault:this.isNewFault,
				       cause:this.cause,
				       dealProgress:this.dealProgress,
				       stopDuration:this.stopDuration,
				       lostPower:this.lostPower,
				       oneLostPower:this.oneLostPower,
				       unlimitDuration:this.unlimitDuration,
				       lastEditCode:this.currentUser.userId,
				       lastEditName:this.currentUser.name,
				       lastEditTime:this.nowDate,
				       faultSys:this.faultSys,
			}
			mui.neiosRequst.httpRequst('/app/neiosShutdownRecord/add', param,
							(data)=> {
							if(data.code ==  0){
								mui.toast("保存成功")
								setTimeout(function() {
									location.reload();
								}, 1000);
							}
							else{
								mui.toast(data.msg)
							}
			
							},
							function(data) {
			
							})
		},
		//保存提交
		save(e){
			var param = {
				bizTypeId:'RSP',
				checkCode:this.currentUser.userId,
				checkDate:'',
				checkName:this.currentUser.name,
				newAreaCode:this.currentUser.companyNewCode,
				remark:'',
				submitType:e,
				workId:this.workId,
				neiosBooster:this.list
			}
			console.log(JSON.stringify(param))
			return
			mui.neiosRequst.httpRequst('/app/booster/create', param,
							(data)=> {
							if(data.code ==  0){
								mui.toast("保存成功")
								setTimeout(function() {
									location.reload();
								}, 1000);
							}
							else{
								mui.toast(data.msg)
							}
			
							},
							function(data) {
			
							})
		},

		//获取列表
		getList(){
			var that = this
			var param = {
				bizTypeId:'RSP',
				// deviceCode:'',
				keywords:this.keyWords,
				newAreaCode:this.currentUser.companyNewCode,
				newStationCode:this.currentUser.stationNewCode,
				pageIndex:this.pageIndex,
				pageSize:999,
				// shutdownEndTime:'',
				// shutdownStartTime:'',
				// shutdownType:'',
				startArr:[],
				status:this.status,
				system:''
			}
			mui.neiosRequst.httpRequst('/app/neiosShutdownRecord/list', param,
							(data)=> {
				that.list = data.data.records
							},
							function(data) {

							})
							
		},
		//返回
		goBack(){
			mui.back()
		},
	}

})